import 'package:efood_multivendor/data/model/response/product_model.dart';

class PlaceOrderBody {
  late List<Cart> _cart;
  late double _couponDiscountAmount;
  late String _couponDiscountTitle;
  late double _orderAmount;
  late String _orderType;
  late String _paymentMethod;
  late String _orderNote;
  late String _couponCode;
  late int _restaurantId;
  late double _distance;
  late String _scheduleAt;
  late double _discountAmount;
  late double? _taxAmount;
  late String _address;
  late String _latitude;
  late String _longitude;
  late String _contactPersonName;
  late String _contactPersonNumber;
  late String _addressType;
  late double? _tip;
  late String? _alternativePhoneNumber;
  late String _referredBy;
  late bool _callOnArrival;

  PlaceOrderBody(
      {required List<Cart> cart,
      required double couponDiscountAmount,
      required String couponDiscountTitle,
      required String couponCode,
      required double orderAmount,
      required String orderType,
      required String paymentMethod,
      required int restaurantId,
      required double distance,
      required String scheduleAt,
      required double discountAmount,
      double? taxAmount,
      required String orderNote,
      required String address,
      required String latitude,
      required String longitude,
      required String contactPersonName,
      required String contactPersonNumber,
      required String addressType,
      double? tip,
      String? alternativePhoneNumber,
      required String referredBy,
      required bool callOnArrival}) {
    this._cart = cart;
    this._couponDiscountAmount = couponDiscountAmount;
    this._couponDiscountTitle = couponDiscountTitle;
    this._orderAmount = orderAmount;
    this._orderType = orderType;
    this._paymentMethod = paymentMethod;
    this._orderNote = orderNote;
    this._couponCode = couponCode;
    this._restaurantId = restaurantId;
    this._distance = distance;
    this._scheduleAt = scheduleAt;
    this._discountAmount = discountAmount;
    this._taxAmount = taxAmount;
    this._address = address;
    this._latitude = latitude;
    this._longitude = longitude;
    this._contactPersonName = contactPersonName;
    this._contactPersonNumber = contactPersonNumber;
    this._addressType = addressType;
    this._tip = tip;
    this._alternativePhoneNumber = alternativePhoneNumber;
    this._referredBy = referredBy;
    this._callOnArrival = callOnArrival;
  }

  List<Cart> get cart => _cart;
  double get couponDiscountAmount => _couponDiscountAmount;
  String get couponDiscountTitle => _couponDiscountTitle;
  double get orderAmount => _orderAmount;
  String get orderType => _orderType;
  String get paymentMethod => _paymentMethod;
  String get orderNote => _orderNote;
  String get couponCode => _couponCode;
  int get restaurantId => _restaurantId;
  double get distance => _distance;
  String get scheduleAt => _scheduleAt;
  double get discountAmount => _discountAmount;
  double? get taxAmount => _taxAmount;
  String get address => _address;
  String get latitude => _latitude;
  String get longitude => _longitude;
  String get contactPersonName => _contactPersonName;
  String get contactPersonNumber => _contactPersonNumber;
  String? get alternativePhoneNumber => _alternativePhoneNumber;
  String get referredBy => _referredBy;
  bool get callOnArrival => _callOnArrival;

  PlaceOrderBody.fromJson(Map<String, dynamic> json) {
    if (json['cart'] != null) {
      _cart = [];
      json['cart'].forEach((v) {
        _cart.add(new Cart.fromJson(v));
      });
    }
    _couponDiscountAmount = json['coupon_discount_amount'];
    _couponDiscountTitle = json['coupon_discount_title'];
    _orderAmount = json['order_amount'];
    _orderType = json['order_type'];
    _paymentMethod = json['payment_method'];
    _orderNote = json['order_note'];
    _couponCode = json['coupon_code'];
    _restaurantId = json['restaurant_id'];
    _distance = json['distance'];
    _scheduleAt = json['schedule_at'];
    _discountAmount = json['discount_amount'].toDouble();
    _taxAmount = json['tax_amount'].toDouble();
    _address = json['address'];
    _latitude = json['latitude'];
    _longitude = json['longitude'];
    _contactPersonName = json['contact_person_name'];
    _contactPersonNumber = json['contact_person_number'];
    _addressType = json['address_type'];
    _tip = json['tip'];
    _alternativePhoneNumber = json['contact_person_alternative_number'];
    _referredBy = json['referred_by'];
    _callOnArrival = json['call_on_arrival'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this._cart.isNotEmpty) {
      data['cart'] = this._cart.map((v) => v.toJson()).toList();
    }
    data['coupon_discount_amount'] = this._couponDiscountAmount;
    data['coupon_discount_title'] = this._couponDiscountTitle;
    data['order_amount'] = this._orderAmount;
    data['order_type'] = this._orderType;
    data['payment_method'] = this._paymentMethod;
    data['order_note'] = this._orderNote;
    data['coupon_code'] = this._couponCode;
    data['restaurant_id'] = this._restaurantId;
    data['distance'] = this._distance;
    data['schedule_at'] = this._scheduleAt;
    data['discount_amount'] = this._discountAmount;
    data['tax_amount'] = this._taxAmount;
    data['address'] = this._address;
    data['latitude'] = this._latitude;
    data['longitude'] = this._longitude;
    data['contact_person_name'] = this._contactPersonName;
    data['contact_person_number'] = this._contactPersonNumber;
    data['address_type'] = this._addressType;
    data['tip'] = this._tip;
    data['contact_person_alternative_number'] = this.alternativePhoneNumber;
    data['referred_by'] = this.referredBy;
    data['call_on_arrival'] = this.callOnArrival;
    return data;
  }

  PlaceOrderBody copyWith({String? pMethod}) => PlaceOrderBody(
      cart: this._cart,
      couponDiscountAmount: this._couponDiscountAmount,
      couponDiscountTitle: this._couponDiscountTitle,
      couponCode: this._couponCode,
      orderAmount: this._orderAmount,
      orderType: this._orderType,
      paymentMethod: pMethod ?? '',
      restaurantId: this._restaurantId,
      distance: this._distance,
      scheduleAt: this._scheduleAt,
      discountAmount: this._discountAmount,
      taxAmount: this._taxAmount,
      orderNote: this._orderNote,
      address: this._address,
      latitude: this._latitude,
      longitude: this._longitude,
      contactPersonName: this._contactPersonName,
      contactPersonNumber: this._contactPersonNumber,
      addressType: this._addressType,
      tip: this._tip,
      alternativePhoneNumber: this._alternativePhoneNumber,
      referredBy: this._referredBy,
      callOnArrival: this._callOnArrival);
}

class Cart {
  int? _foodId;
  int? _itemCampaignId;
  String? _price;
  String? _variant;
  List<Variation>? _variation;
  int? _quantity;
  List<int>? _addOnIds;
  List<AddOns>? _addOns;
  List<int>? _addOnQtys;

  Cart(
      int? foodId,
      int? itemCampaignId,
      String? price,
      String? variant,
      List<Variation>? variation,
      int? quantity,
      List<int>? addOnIds,
      List<AddOns>? addOns,
      List<int>? addOnQtys) {
    this._foodId = foodId;
    this._itemCampaignId = itemCampaignId;
    this._price = price;
    this._variant = variant;
    this._variation = variation;
    this._quantity = quantity;
    this._addOnIds = addOnIds;
    this._addOns = addOns;
    this._addOnQtys = addOnQtys;
  }

  int? get foodId => _foodId;
  int? get itemCampaignId => _itemCampaignId;
  String? get price => _price;
  String? get variant => _variant;
  List<Variation>? get variation => _variation;
  int? get quantity => _quantity;
  List<int>? get addOnIds => _addOnIds;
  List<AddOns>? get addOns => _addOns;
  List<int>? get addOnQtys => _addOnQtys;

  Cart.fromJson(Map<String, dynamic> json) {
    _foodId = json['food_id'];
    _itemCampaignId = json['item_campaign_id'];
    _price = json['price'];
    _variant = json['variant'];
    if (json['variation'] != null) {
      _variation = [];
      json['variation'].forEach((v) {
        _variation?.add(new Variation.fromJson(v));
      });
    }
    _quantity = json['quantity'];
    _addOnIds = json['add_on_ids'].cast<int>();
    if (json['add_ons'] != null) {
      _addOns = [];
      json['add_ons'].forEach((v) {
        _addOns?.add(new AddOns.fromJson(v));
      });
    }
    _addOnQtys = json['add_on_qtys'].cast<int>();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['food_id'] = this._foodId;
    data['item_campaign_id'] = this._itemCampaignId;
    data['price'] = this._price;
    data['variant'] = this._variant;
    if (this._variation != null) {
      data['variation'] = this._variation?.map((v) => v.toJson()).toList();
    }
    data['quantity'] = this._quantity;
    data['add_on_ids'] = this._addOnIds;
    if (this._addOns != null) {
      data['add_ons'] = this._addOns?.map((v) => v.toJson()).toList();
    }
    data['add_on_qtys'] = this._addOnQtys;
    return data;
  }
}

class PaymentBody {
  int? orderId;
  String? paymentMethod;
  String? deviceType;

  PaymentBody(this.orderId, this.paymentMethod, this.deviceType);

  PaymentBody.fromJson(Map<String, dynamic> json) {
    orderId = json['order_id'];
    paymentMethod = json['payment_method'];
    deviceType = json['device_type'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['order_id'] = this.orderId;
    data['payment_method'] = this.paymentMethod;
    data['device_type'] = this.deviceType;
    return data;
  }
}

class UnpaidIncompletePaymentBody {
  double? orderAmount;
  String? paymentMethod;

  UnpaidIncompletePaymentBody(this.orderAmount, this.paymentMethod);

  UnpaidIncompletePaymentBody.fromJson(Map<String, dynamic> json) {
    orderAmount = json['order_amount'];
    paymentMethod = json['payment_method'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();

    data['order_amount'] = this.orderAmount;
    data['payment_method'] = this.paymentMethod;
    return data;
  }
}
